package leetcode.code1760;

import java.util.TreeMap;

import leetcode.IDebug;

// 正面突破 贪心求解，修罗修罗啊
public class Solution implements IDebug {

	public int minimumSize(int[] nums, int maxOperations) {
		TreeMap<Integer, Integer> tm = new TreeMap<>();
		for (int num : nums) {
			int count = tm.getOrDefault(num, 0);
			tm.put(num, count + 1);
		}
		while (maxOperations > 0) {
			int big = tm.lastKey();
			int small = tm.firstKey();
			if (big != small) {
				int bigCnt = tm.getOrDefault(big, 0);
				if (bigCnt > 1) {
					tm.put(big, bigCnt - 1);
				}
				int smallCnt = tm.get(small);
				tm.put(small, smallCnt + 1);
				int sb = big - small;
				int sbCnt = tm.getOrDefault(sb, 0);
				tm.put(sb, sbCnt + 1);
			} else {
				if (big > 1) {
					int half = big >> 1;
				}
			}
		}
		return tm.lastKey();
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
